package cn.jbt.api.admin.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.annotations.ColumnDefault;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.util.Date;


@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@EntityListeners(AuditingEntityListener.class)
@Entity
@Table(name = "xxl_job_log", schema = "jbt")
public class XxlJobLog {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

    @NotNull
    @Column(name = "job_group", nullable = false)
    private Integer jobGroup;

    @NotNull
    @Column(name = "job_id", nullable = false)
    private Integer jobId;

    @Size(max = 255)
    @Column(name = "executor_address")
    private String executorAddress;

    @Size(max = 255)
    @Column(name = "executor_handler")
    private String executorHandler;

    @Size(max = 512)
    @Column(name = "executor_param", length = 512)
    private String executorParam;

    @Size(max = 20)
    @Column(name = "executor_sharding_param", length = 20)
    private String executorShardingParam;

    @NotNull
    @ColumnDefault("0")
    @Column(name = "executor_fail_retry_count", nullable = false)
    private Integer executorFailRetryCount;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "trigger_time")
    private Date triggerTime;

    @NotNull
    @Column(name = "trigger_code", nullable = false)
    private Integer triggerCode;

    @Lob
    @Column(name = "trigger_msg")
    private String triggerMsg;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "handle_time")
    private Date handleTime;

    @NotNull
    @Column(name = "handle_code", nullable = false)
    private Integer handleCode;

    @Lob
    @Column(name = "handle_msg")
    private String handleMsg;

    @NotNull
    @ColumnDefault("0")
    @Column(name = "alarm_status", nullable = false)
    private Integer alarmStatus;

    /* 定时任务信息 */
    @Transient
    private XxlJobInfo xxlJobInfo;
    /* 调度状态：1-成功 2-失败 3-处理中 */
    @Transient
    private Integer logStatus = 0;
    /* 创建开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Transient
    private Date createTimeStart;
    /* 创建结束时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Transient
    private Date createTimeEnd;
}